package com.jzo2o.foundations.controller.operation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jzo2o.common.expcetions.ForbiddenOperationException;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.enums.FoundationStatusEnum;
import com.jzo2o.foundations.mapper.ServeItemMapper;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.domain.ServeItem;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author asus
 */
@RequiredArgsConstructor
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {
    private final IServeService serveService;

    /**
     * 区域服务分页查询
     *
     * @param servePageQueryReqDTO
     * @return PageResult<ServeResDTO>
     */
    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        PageResult<ServeResDTO> page = serveService.page(servePageQueryReqDTO);
        return page;
    }

    /**
     * 新增区域服务
     *
     * @param serveUpsertReqDTOList
     * @return void
     */
    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList) {
        serveService.batchAdd(serveUpsertReqDTOList);
    }

    /**
     * 修改区域服务价格
     *
     * @param price serveItemId
     * @return void
     */
    @PutMapping("/{id}")
    @ApiOperation("区域服务修改价格")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
            @ApiImplicitParam(name = "price", value = "服务价格", required = true),
    })
    public void update(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        serveService.update(id, price);
    }

    /**
     * 上架区域服务
     *
     * @param id
     * @return void
     */
    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
    })
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }

    /**
     * 删除区域服务
     *
     * @param id
     * @return void
     */
    @DeleteMapping("/{id}")
    @ApiOperation("区域服务删除")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
    })
    public void delete(@PathVariable("id") Long id) {
        serveService.delete(id);
    }

    /**
     * 下架区域服务
     *
     * @param id
     * @return void
     */
    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
    })
    public void offSale(@PathVariable("id") Long id) {
        serveService.offSale(id);
    }

    /**
     * 设置区域服务热门
     *
     * @param id
     * @return void
     */
    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设置热门")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
    })
    public void setHot(@PathVariable("id") Long id) {
        serveService.setHot(id);
    }

    /**
     * 设置区域服务非热门
     *
     * @param id
     * @return void
     */
    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "服务id", required = true),
    })
    public void offHot(@PathVariable("id") Long id) {
        serveService.offHot(id);
    }

}